package com.zhang.zhangapp.view.custom;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.zhang.zhangapp.R;
import com.zhang.zhangapp.utils.ScreenUtils;

import org.xutils.view.annotation.ContentView;
import org.xutils.x;

/**
 * Created by 罗肖 on 2018/4/10.
 */

public class EditDialog extends Dialog {

    TextView sureText;
    EditText editText;
    TextView titleText;
    String title;
    String value;

    public EditDialog(@NonNull Context context, String title, String value) {
        super(context, R.style.CustomDialogStyle);
        this.title = title;
        this.value = value;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_dialog);
        sureText = findViewById(R.id.dialog_sure_btn);
        titleText = findViewById(R.id.edit_dialog_title);
        editText = findViewById(R.id.dialog_edit);
        titleText.setText(title);
        editText.setHint(title);
        editText.setText(value);

        WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
        layoutParams.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 0.7);
        layoutParams.height = (int) (ScreenUtils.getScreenWidth(getContext()) * 0.7 / 2);
        this.getWindow().setGravity(Gravity.CENTER);
        this.getWindow().setAttributes(layoutParams);
    }

    public void setOnSureClickListenrer(View.OnClickListener listenrer) {
        sureText.setOnClickListener(listenrer);
    }

    public String getText() {
        return editText.getText().toString() == null ? "" : editText.getText().toString();
    }
}
